//package com.yzf.enterprise.framework.config.shardingjdbc;
//
//import com.google.common.collect.Range;
//import io.shardingsphere.api.algorithm.sharding.RangeShardingValue;
//import io.shardingsphere.api.algorithm.sharding.standard.RangeShardingAlgorithm;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.Collection;
//import java.util.LinkedHashSet;
//
///**
// * 范围查询所使用的分片算法
// */
//@Slf4j
//public class TblRangeShardAlgo implements RangeShardingAlgorithm<String> {
//
//    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//
//    @Override
//    public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<String> rangeShardingValue) {
//        log.info("This is Table RangeShardingAlgorithm , availableTargetNames:" + availableTargetNames);
//        log.info("This is Table RangeShardingAlgorithm , rangeShardingValue:" + rangeShardingValue);
//
//        Collection<String> collect = new LinkedHashSet<>();
//
//        // 按月分表
//        Range<String> valueRange = rangeShardingValue.getValueRange();
//        String lowerStr = valueRange.lowerEndpoint();
//        String upperStr = valueRange.upperEndpoint();
//        int lowerMonth = LocalDateTime.parse(lowerStr, dtf).getMonth().getValue();
//        int upperMonth = LocalDateTime.parse(upperStr, dtf).getMonth().getValue();
//        log.info("lowerMonth:{}", lowerMonth);
//        log.info("upperMonth:{}", upperMonth);
//
//        for (int i = lowerMonth; i <= upperMonth; i++) {
//            for (String tableName : availableTargetNames) {
//                if (tableName.endsWith("_" + i)) {
//                    collect.add(tableName);
//                }
//            }
//        }
//        return collect;
//    }
//
//}